﻿module Lhz.Page.DataManagement {
    export class ServiceDetail extends DetailPage<Lhz.Entity.ServiceCenter.Service> {
        constructor() {
            super({
                serviceNo: "service",
                mappingOptionsArray: [
                    { propertyName: "ApplicationGuid", selector: "[name=ApplicationGuid]" },
                    { propertyName: "No", selector: "[name=No]" },
                    { propertyName: "Name", selector: "[name=Name]" },
                    { propertyName: "Url", selector: "[name=Url]" },
                    { propertyName: "Description", selector: "[name=Description]" }
                ],
                initiate: function (dp, initCallback) {
                    dp.sci.InvokeByInvokeArgument<Lhz.Entity.ServiceCenter.Application[]>({
                        serviceNo: "application",
                        operationNo: "query",
                        arguments: [null],
                        successCallback: function (result, data) {
                            var dp: DetailPage<Lhz.Entity.ServiceCenter.Service> = data;
                            dp.bindSelect("[name=ApplicationGuid]", result.Result, "Guid", "Name");
                            initCallback(dp);
                        },
                        data: dp
                    });
                },
                createItem: function (dp) {
                    return new Lhz.Entity.ServiceCenter.Service();
                },
                saveStart: function (dp) {
                    for (var operation of dp.item.Operations) {
                        operation.Guid = dp.sci.getGuid();
                        operation.ServiceGuid = dp.item.Guid;
                    }
                },
                initialized: function (dp) {
                    new ManagementPage<Lhz.Entity.ServiceCenter.Operation>({
                        dbOperation: false,
                        targetName: "操作",
                        colModel: [
                            { title: "名称", dataIndx: "Name", width: "200", align: "center" },
                            { title: "编号", dataIndx: "No", width: "200", align: "center" },
                            { title: "描述", dataIndx: "Description", width: "300" }
                        ],
                        detailPageUrl: "operation-detail.html",
                        width: 400,
                        height: 200,
                        data: dp.item.Operations,
                        getItemName: function (mp, item) {
                            return item.Name;
                        }
                    });
                }
            });
        }
    }
    $(function () {
        new ServiceDetail();
    });
}
